<template>
	<view class="content">

		<view class="top-bg">
			<!-- <text class="top-title">个人中心</text> -->
		</view>

		<view class="main_body ">
			<view class="top-card card-type">
				<!-- <image src="../../static/user_photo.png"></image> -->
				<view class="user-area" style="padding-left: 30rpx;">

					<view v-if="isLogin == false" @click="navClick('../auth/login')">点击进行登陆</view>
					<view v-else>
						<image :src="BaseInfo.HeadImg" class="avatar" mode="widthFix">
						</image>
						<view class="info-list">
							<text>用户名:{{BaseInfo.NickName}}</text>
							<!-- <text>账号:{{BaseInfo.Mobile}}</text> -->
						</view>

					</view>
				</view>
				<!-- <view   @click="navClick('mySetting/mySetting')">更改</view> -->


			</view>
			<view class="middle-card card-type">
				<view class="middle-item" v-for="(item,index) in middleList" :key="index" @click="navClick(item.url)">
					<view class="item-left">
						<image :src="item.imageUrl" style="width: 60rpx;" mode="widthFix"></image>
					</view>
					<view class="item-right">
						<view>
							<text>{{item.name}}</text>
						</view>
						<view>
							<u-icon size="30" name="arrow-right"></u-icon>
						</view>
					</view>
				</view>

			</view>
			<view class="middle-card card-type">

				<view class="middle-item" v-for="(item,index) in nurseList" :key="index" @click="navClick(item.url)">
					<view class="item-left">
						<image :src="item.imageUrl" style="width: 60rpx;" mode="widthFix"></image>
					</view>
					<view class="item-right">
						<view>
							<text>{{item.name}}</text>
						</view>
						<view>
							<u-icon size="30" name="arrow-right"></u-icon>
						</view>
					</view>


				</view>
			</view>

		</view>

		<view class="bottom_button" v-if="isLogin == true">

			<view>
				<u-button @click="logOut" :plain="true" type="primary" shape="circle">退出登录</u-button>
			</view>

		</view>



	</view>
</template>

<script>
	import {
		mapState,
		mapGetters,
		mapMutations
	} from 'vuex';
	import setter from '@/config.js';
	export default {
		data() {
			return {
				isNurse: 0,
				isLogin: false,
				setter,
				BaseInfo: {
					HeadImg: '',
				},
				// 认证信息
				IdentityInfo: {
					Type: 1,
					IdentityStatus: 1,
					IndustryId: '',
					FullName: '',
					CoTaxNo: '',
					Person: '',
					Mobile: '',
					CardNo: '',
					Province: '',
					ProvinceId: '',
					City: '',
					CityId: '',
					County: '',
					CountyId: '',
					Town: '',
					TownId: '',
					Address: '',
					ContractArea: 0,
					CardFrontImg: '',
					CardBackImg: '',
					CoLicenseImg: '',
					IdentityReason: ''
				},
				badgeData: {
					unreadMsg: 0
				},
				version: '1.0.0', //APP版本号
				user: {},
				userState: false,
				middleList: [
					// {
					// 	imageUrl:"/static/icon/xfjl.png",
					// 	name:"消费记录",
					// 	url:"middleFun/beNursed/beNursed?chooseFlag"
					// },
					{
						imageUrl: "/static/icon/ghjlc.png",
						name: "挂号记录",
						url: "/pages/register/Scheduling/record/record"
					},
					// {
					// 	imageUrl:"/static/icon/fpsq.png",
					// 	name:"邮寄记录",
					// 	url:"/pages/My/fapiao/fapiao"
					// },


				],
				nurseList: [{
					imageUrl: "/static/icon/gzc.png",
					name: "关注的医生",
					url: "/pages/doctor/brscys"
				}]

			}
		},
		onLoad() {
			// #ifdef MP-WEIXIN
			this.version = wx.getAccountInfoSync().miniProgram.version || '1.0.0'; // 小程序 版本号
			// #endif

		},
		onShow() {
			if (this.hasLogin) {
				this.$store.dispatch('getUserInfo');
				this.isNurse = this.$store.state.isnurse
				this.user = this.$store.state.userInfo
				this.userState = true
				this.isLogin = true
				// this.totalMessage().then(res => {
				//     this.badgeData.unreadMsg = res;
				// });
			}
		},
		computed: {
			...mapState(['userInfo']),
			...mapGetters(['hasLogin', 'getUserInfo'])

		},
		watch: {
			userInfo(val) {

				Object.assign(this.BaseInfo, val);
				Object.assign(this.IdentityInfo, val.IdentityInfo);

			}
		},
		methods: {
			...mapMutations(['logout']),
			//退出
			logOut() {
				let that = this;
				that.$dialog.confirm('提示', '您确定要退出系统？').then(res => {
					if (res) {
						that.$dialog.loading('退出中...');
						that.$request('auth', 'logout').then(() => {
							that.$dialog.msg('退出成功', 500).then(() => {
								that.logout();
								// uni.reLaunch({
								//     url: '/pages/index/index'
								// });
								this.closeBrowser()
							});
						});
					}
				});
			},
			closeBrowser() {
				// 判断苹果手机内置浏览器
				var ua = navigator.userAgent.toLowerCase();
				if (window.WeixinJSBridge) {
					//这个可以关闭安卓系统的手机
					document.addEventListener("WeixinJSBridgeReady", function() {
						WeixinJSBridge.call("closeWindow");
					}, false);
					//这个可以关闭ios系统的手机
					WeixinJSBridge.call("closeWindow")
				} else if (navigator.userAgent.indexOf("Firefox") != -1 || navigator.userAgent.indexOf("Chrome") != -1) {
					window.location.href = "about:blank";
					window.opener = null;
					window.open('about:blank', '_self', '').close();

				} else if (ua.indexOf('applewebkit') > -1 && ua.indexOf('mobile') > -1 && ua.indexOf('safari') > -1 &&
					ua.indexOf('linux') === -1 && ua.indexOf('android') === -1 && ua.indexOf('chrome') === -1 &&
					ua.indexOf('ios') === -1 && ua.indexOf('browser') === -1) {
					window.location.href = "about:blank";
					window.opener = null;
					window.open('about:blank', '_self', '').close();

				} else {
					window.close();
				}

			},

			navClick(url) {

				if (url) {
					uni.navigateTo({
						url,
						fail(error) {
							console.log(error)
						}
					})
				} else {
					this.show = true
				}

			}

		}
	}
</script>

<style>
	@import './My.css';
</style>